package org.zanpu.metadataserver.core.util;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * Created by MD on 2016/11/10.
 */
public class ValuesUtil {

    public static String insertValues(Map<String, Object> map){
        StringBuffer columns = new StringBuffer(" ( ");
        StringBuffer values = new StringBuffer(" VALUES( ");
        map.keySet().stream().peek(key -> map.put(key, (map.get(key) instanceof java.lang.String) ? "'" + map.get(key) + "'" :map.get(key)
        )).forEach(key -> {
            columns.append("`" + key + "`,");
            values.append(map.get(key) + ",");
        });
        columns.deleteCharAt(columns.length()-1).append(")");values.deleteCharAt(values.length()-1).append(")");

        return columns.toString()+values.toString();
    }

    public static Map putAll(Map map1,Map map2){
        map1.putAll(map2);
        return map1;
    }
}
